package com.atguigu.zhxy.controller;

import com.atguigu.zhxy.pojo.Student;
import com.atguigu.zhxy.service.StudentService;
import com.atguigu.zhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "学生控制器")
@RestController
@RequestMapping("/sms/studentController")
public class StudentController {
    @Autowired
    private StudentService studentService ;

    @ApiOperation("获取全部学生")
    @GetMapping("/getStudentByOpr/{pageNum}/{pageSize}")
    public Result getStudentByOpr(
            @ApiParam("分页查询的页码数")@PathVariable("pageNum") Integer pageNum,
            @ApiParam("分页查询的记录数")@PathVariable("pageSize") Integer pageSize,
            @ApiParam("查询条件")Student student
            ){
        //        分页带条件查询
        Page<Student> page = new Page<>(pageNum, pageSize);
//        通过服务层
        IPage<Student> gradeIPage = studentService.getGradesByPN(page,student);
//        封装result对象并返回
        return Result.ok(gradeIPage) ;
    }
    @ApiOperation("新增或修改学生")
    @PostMapping("/addOrUpdateStudent")
    public Result addOrUpdateStudent(@RequestBody Student student){
        studentService.saveOrUpdate(student) ;
        return Result.ok() ;
    }
    @ApiOperation("删除学生")
    @DeleteMapping("/delStudentById")
    public Result delStudentById(@RequestBody List<Integer> idList){
        studentService.removeByIds(idList) ;
        return Result.ok() ;
    }
}
